﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;

namespace DARE
{
    /// <summary>
    /// 
    /// </summary>
    public class CResourcesList : CEnumeratorHelper<string>
    {
        #region Fields

        private Dictionary<string, int> m_resources;

        #endregion

        #region CTOR

        public CResourcesList()
        {
            m_resources = new Dictionary<string, int>();
        }

        #endregion

        #region Method

        internal void AddAsset(string assetPath)
        {
            //Debug.Assert(!this.Contains(assetPath));
            if (!this.m_resources.ContainsKey(assetPath))
                this.m_resources.Add(assetPath, 0);
            ++this.m_resources[assetPath];
        }

        internal void RemoveAsset(string assetPath)
        {
            if (this.m_resources.ContainsKey(assetPath))
            {
                --this.m_resources[assetPath];
                if (this.m_resources[assetPath] <= 0)
                    this.m_resources.Remove(assetPath);
            }
        }

        protected override bool ValidateEnumerator(int index)
        {
            if (this.m_resources.Count > index)
            {
                base.m_current = this.m_resources.ElementAt(index).Key;
                return true;
            }
            return false;
        }

        #endregion

    }
}
